"""
-*- coding: utf-8 -*-

@author: Du Changping
@time: 2021/12/2 15:27
@file name: txt2spc
@software：PyCharm

Do not smash your computer!

"""

import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt


def txt2spc(file_name_: str):
    cur_path_ = os.getcwd()
    energy_spec_path_ = os.path.join(cur_path_, file_name_)
    print(energy_spec_path_)

    energy_spec_ = pd.read_table(energy_spec_path_, sep="   ", engine="python")
    energy_spec_["1"] = energy_spec_["1"].apply(lambda x: 1000 * x)
    save_name_ = energy_spec_name.split(".")[:-1][0] + ".spc"
    save_path_ = os.path.join(cur_path_, save_name_)
    np.savetxt(save_path_, energy_spec_.values, delimiter="   ")


if __name__ == "__main__":
    cur_path = os.getcwd()
    energy_spec_name = r"liuhanxi_task.txt"

    txt2spc(energy_spec_name)
    # energy_spec_path = os.path.join(cur_path, energy_spec_name)
    #
    # energy_spec = pd.read_table(energy_spec_path, sep="   ", engine="python")
    # energy_spec["1"] = energy_spec["1"].apply(lambda x: 1000 * x)
    # save_name = energy_spec_name.split(".")[:-1][0] + ".spc"
    # save_path = os.path.join(cur_path, save_name)
    # np.savetxt(save_path, energy_spec.values, delimiter="   ")
    print(2)
